import Http from '../http';
import type { 
  Banner, 
  BannerQueryParams, 
  BannerListResponse, 
  CreateBannerRequest, 
  UpdateBannerRequest,
  BannerStatsResponse
} from '@/types/banner';

/**
 * 轮播图管理API
 */
export class BannerApi {
  /**
   * 获取轮播图列表
   */
  static getBannerList(params: BannerQueryParams): Promise<BannerListResponse> {
    return Http.get('/api/banners', { params });
  }

  /**
   * 获取轮播图详情
   */
  static getBannerById(id: number): Promise<Banner> {
    return Http.get(`/api/banners/${id}`);
  }

  /**
   * 创建轮播图
   */
  static createBanner(data: CreateBannerRequest): Promise<Banner> {
    return Http.post('/api/banners', data);
  }

  /**
   * 更新轮播图
   */
  static updateBanner(id: number, data: UpdateBannerRequest): Promise<Banner> {
    return Http.put(`/api/banners/${id}`, data);
  }

  /**
   * 删除轮播图
   */
  static deleteBanner(id: number): Promise<void> {
    return Http.delete(`/api/banners/${id}`);
  }

  /**
   * 批量删除轮播图
   */
  static batchDeleteBanners(ids: number[]): Promise<void> {
    return Http.post('/api/banners/batch-delete', { ids });
  }

  /**
   * 更新轮播图状态
   */
  static updateBannerStatus(id: number, status: number): Promise<Banner> {
    return Http.patch(`/api/banners/${id}/status`, { status });
  }

  /**
   * 获取轮播图统计信息
   */
  static getBannerStats(): Promise<BannerStatsResponse> {
    return Http.get('/api/banners/stats');
  }

  /**
   * 获取公开轮播图列表（前台使用）
   */
  static getPublicBanners(position?: string): Promise<Banner[]> {
    const params = position ? { position } : {};
    return Http.get('/api/public/banners', { params });
  }
}

export default BannerApi;